var singlePriceData = {};
    singlePriceData.key="";
    var singleTable;
    jQuery(document).ready(function () {
    	singleTable = jQuery('#singlePumpPriceTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "iDisplayLength": 4,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url":window.rootPath+ '/ui/priceBook/singlePump/getpage',
                "data": function (d) {
                    return $.extend({}, d, singlePriceData);
                }
            },
            columns: [
                {
                    data: null,
                    defaultContent: ""// 排序
                },
                {
                    data: null,
                    defaultContent: "",
                    render: function (data, type, full, meta) {
                        var id=data.id
                        var operate ='<input type="checkbox" class="checkchildPump">';
                        return operate;
                    }
                },
                {
                    data: 'device.deviceType'
                },
                {
                    data: 'device.deviceModel'
                },
                {
                    data: 'superior'
                },
                {
                    data: 'price'
                }
            ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    });
    
 // //加载成套的价格表
	var deviceData = {};
	deviceData.key='';
    var devicePriceTable;
    jQuery(document).ready(function () {
    	devicePriceTable = jQuery('#devicePriceTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "iDisplayLength": 4,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url":window.rootPath+ '/ui/priceBook/equipment/getpage',
                "data": function (d) {
                    return $.extend({}, d, deviceData);
                }
            },
            columns: [
                {
                    data: null,
                    defaultContent: ""// 排序
                },
                {
                    data: null,
                    defaultContent: "",
                    render: function (data, type, full, meta) {
                        var id=data.id
                        var operate ='<input type="checkbox" class="checkchildEquipment">';
                        return operate;
                    }
                },
                {
                    data: 'wholeSetDevice.deviceName'
                },
                {
                    data: 'wholeSetDevice.type'
                },
                {
                    data: 'superior'
                },
                {
                    data: 'price'
                }
                ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }

                
            }
        });
    });

 // ///加载备件的价格表
	 var replaceData = {};
	     replaceData.key='';
	    var replacePriceTable;
	    jQuery(document).ready(function () {
	    	replacePriceTable = jQuery('#replacePriceTable').DataTable({
	            "serverSide": true,
	            "ordering": false,
	            "iDisplayLength": 4,
	            "ajax": {
	                "dataType": "json",
	                "type": "get",
	                "cache": false,
	                "url":window.rootPath+ '/ui/priceBook/replaceDevice/getpage',
	                "data": function (d) {
	                    return $.extend({}, d, replaceData);
	                }
	            },
	            columns: [
	                {
	                    data: null,
	                    defaultContent: ""// 排序
	                },
	                {
	                    data: null,
	                    defaultContent: "",
	                    render: function (data, type, full, meta) {
	                        var id=data.id
	                        var operate ='<input type="checkbox" class="checkchildReplaceDevice">';
	                        return operate;
	                    }
	                },
	                {
	                    data: 'replacementDevice.deviceName'
	                },
	                {
	                    data: 'replacementDevice.type'
	                },
	                {
	                    data: 'replacementDevice.material'
	                },
	                {
	                    data: 'superior'
	                },
	                {
	                    data: 'price'
	                }
	            ],
	            "drawCallback": function (oSettings) {
	                var k = 0;
	                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

	                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
	                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
	                    k++;
	                }
	            }
	        }); 
	    });
	    
	 // /引入主机或成套设备的价格
	 // 引入主机或成套设备的价格弹窗
	 	 jQuery('#queryDevice').on("click",function(){
	 		 jQuery("#queryDevicePriceModal").modal('show');
	 	 });
	 	// 引入主机或成套设备
	 	 jQuery('#pull-in-devicePrice').on("click",function(){
	 		 var select1s=getSelect("#singlePumpPriceTable",1);
	 		 var select2s=getSelect("#devicePriceTable",1);
	 		 if((select1s.length>1 && select2s.length>1) || (select1s.length>1 && select2s.length==0) 
	 				 || (select1s.length==0 && select2s.length>1) || (select1s.length==1 && select2s.length==1) ){
	 			 $.springLemonDialog({
	    		         content: '只能操作一条记录',// 确认文本
	    		         clickButton: function (sender, modal, index) {// 按钮事件处理
	    		             $(this).closeDialog(modal);
	    		         }
	    		   }); 
	 		 }
	 		 else if(select1s.length==0 && select2s.length==0){
	 	   		   $.springLemonDialog({
	 	   		         content: '请选择要操作的记录',// 确认文本
	 	   		         clickButton: function (sender, modal, index) {// 按钮事件处理
	 	   		             $(this).closeDialog(modal);
	 	   		         }
	 	   		   }); 
	 	   	 }
	 		 else if(select1s.length==1 && select2s.length==0){
	 	   		    jQuery("#productModel").val(select1s[0].device.deviceType);
	 		   		jQuery("#costPrice").val(select1s[0].price);
	 		   		jQuery("#productName").val(select1s[0].device.deviceModel);
	 		   		
	 		   		jQuery("#queryDevicePriceModal").modal('hide');
	 	   	   }
	 		 else if(select1s.length==0 && select2s.length==1){
	 			    jQuery("#productName").val(select2s[0].wholeSetDevice.deviceName);
	 			    jQuery("#productModel").val(select2s[0].wholeSetDevice.type);
	 		   		jQuery("#costPrice").val(select2s[0].price);
	 		   		
	 		   		jQuery("#queryDevicePriceModal").modal('hide');
	 		 }	 		 
	 	 });

	 // 引入备件的价格
	 // /打开弹窗
	 	 jQuery('#queryReplace').on("click",function(){
	 		 jQuery("#queryReplacePriceModal").modal('show');
	 	 });
	 jQuery('#pull-in-replacePrice').on("click",function(){
	 		 var selects=getSelect("#replacePriceTable",1);
	 		   if(selects.length>1){
	 	   		   $.springLemonDialog({
	 	   		         content: '只能操作一条记录',// 确认文本
	 	   		         clickButton: function (sender, modal, index) {// 按钮事件处理
	 	   		             $(this).closeDialog(modal);
	 	   		         }
	 	   		   }); 
	 	   	   }
	 	   	   else if(selects.length==0){
	 	   		   $.springLemonDialog({
	 	   		         content: '请选择要操作的记录',// 确认文本
	 	   		         clickButton: function (sender, modal, index) {// 按钮事件处理
	 	   		             $(this).closeDialog(modal);
	 	   		         }
	 	   		   }); 
	 	   	   }else if(selects.length==1){
	 	   		    jQuery("#deviceName").val(selects[0].replacementDevice.deviceName);
	 		   		jQuery("#type").val(selects[0].replacementDevice.type);
	 		   	    jQuery("#material").val(selects[0].replacementDevice.material);
	 		   		jQuery("#replacePrice").val(selects[0].price);
	 		   		jQuery("#queryReplacePriceModal").modal('hide');
	 	   	   }
	 	 });
	 
	 ////主机设备查询
	 jQuery('.searchSinglePriceBtn').on('click', function() {
		    singlePriceData.key = jQuery('#singlekeyword').val();
		    singleTable.draw();
		})
	 jQuery('.resetSinglePriceBtn').on("click", function() {
			jQuery('#singlekeyword').val('');
			singlePriceData.key = '';
			singleTable.draw();
		});
	 ////成套查询
	 jQuery('.searchDevicePriceBtn').on('click', function() {
		    deviceData.key = jQuery('#devicekeyword').val();
		    devicePriceTable.draw();
		})
	 jQuery('.resetDevicePriceBtn').on("click", function() {
			jQuery('#devicekeyword').val('');
			deviceData.key = '';
			devicePriceTable.draw();
		});
	 
	 
	 ////配件查询
	 jQuery('.searchReplacePriceBtn').on('click', function() {
		    replaceData.key = jQuery('#replacekeyword').val();
		    replacePriceTable.draw();
		})
	 jQuery('.resetReplacePriceBtn').on("click", function() {
			jQuery('#replacekeyword').val('');
			replaceData.key = '';
			replacePriceTable.draw();
		});
	 
	 
	